package com.uam.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.uam.common.annotation.Log;
import com.uam.common.constant.CST;
import com.uam.db.model.dto.TaskListDTO;
import com.uam.db.model.entity.SectorStat;
import com.uam.db.model.entity.TaskStat;
import com.uam.db.model.vo.SectorStatVo;
import com.uam.service.HomeService;
import com.uam.utils.HttpUtils;
import com.uam.web.common.model.BusinessType;
import com.uam.web.common.model.PageRes;
import com.uam.web.common.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author uam
 * @create 2023/12/4 15:01
 * @email uam@uam.com
 */
@Api(tags = "首页接口")
@RestController
@RequestMapping("/home")
public class HomeController {
    @Autowired
    private HomeService homeService;

    @Log(title = "查看首页状态统计", businessType = BusinessType.QUERY_LOG)
    @ApiOperation(value = "首页状态统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户登录token", paramType = "header", required = true)
    })
    @GetMapping("/groupBystatus")
    @ResponseBody
    public Result<List<TaskStat>>  groupBystatus(

    ) {
        return homeService.groupBystatus();
    }

    @Log(title = "查看首页任务列表", businessType = BusinessType.QUERY_LOG)
    @ApiOperation(value = "首页任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户登录token", paramType = "header", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页长度",  required = false),
            @ApiImplicitParam(name = "pageNum", value = "第几页", required = false),
            @ApiImplicitParam(name = "status", value = "status", required = false),
    })
    @GetMapping("/list")
    @ResponseBody
    public Result<PageRes<TaskListDTO>> list(
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) Integer pageNum,
            @RequestParam(required = false) List<String> status) {

        if(pageNum == null || pageNum<0){
            pageNum=0;
        }
        if(pageSize == null || pageSize<=0){
            pageSize=20;
        }
        return homeService.selectTaskList(pageNum, pageSize, status);
    }

    @Log(title = "查看首页扇区统计", businessType = BusinessType.QUERY_LOG)
    @ApiOperation(value = "首页扇区统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户登录token", paramType = "header", required = true),
    })
    @GetMapping("/sectorList")
    @ResponseBody
    public Result<List<SectorStatVo>> sectorList() {
        return homeService.sectorList();
    }


    @Log(title = "查看轨迹", businessType = BusinessType.QUERY_LOG)
    @ApiOperation(value = "轨迹")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户登录token", paramType = "header", required = true),
            @ApiImplicitParam(name = "size", value = "数据条数", dataTypeClass = Integer.class),
    })
    @GetMapping("/route")
    @ResponseBody
    public Result route(@RequestParam(required = false) Integer size

    ) {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("size", size);

        return Result.createSuccess(HttpUtils.get(CST.URL + "/uam/route/track/top", jsonObject));
    }
}
